package recursivecode;

/**
 * 功能描述:递归代码 - 汉诺塔问题 2^n-1 的移动次数
 * 2024/07/10
 *	   |_| 1
 * 	 |____| 2
 * |_______| 3
 * @author ZhangYi
 */
public class HanoiCode {

	public static void main(String[] args) {
		HanoiCode hanoiCode = new HanoiCode();
		hanoiCode.move(5);
	}

	private void move(int n) {
		process(n,"from","to","mid");
	}

	/**
	 * 流程
	 *
	 * @param n     n
	 * @param from  从
	 * @param to    至
	 * @param other 其他: 中转站
	 * @author ZhangYi
	 */
	private void process(int n, String from, String to, String other) {
		if (n == 1) {
			System.out.println(String.format("move %d 层圆盘  %s 至 %s", 1, from, to));
			return;
		}
		process(n - 1, from, other, to);
		System.out.println(String.format("move %d 层圆盘  %s 至 %s", n, from, to));
		process(n - 1, other, to, from);
	}

}
